package com.diaohw.platform.framework.authorization;

import cn.dev33.satoken.exception.*;
import com.diaohw.platform.common.enums.CodeMsgEnum;
import com.diaohw.platform.common.obj.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Configuration
@RestControllerAdvice("com.diaohw")
public class AuthorizationAdvice {

    @ExceptionHandler(NotLoginException.class)
    public Result<?> notLogin(NotLoginException e) {
        return Result.fail(CodeMsgEnum.NOT_LOGIN);
    }

    @ExceptionHandler(NotRoleException.class)
    public Result<?> notRole(NotRoleException e) {
        return Result.fail(CodeMsgEnum.NOT_ROLE.status, e.getMessage());
    }

    @ExceptionHandler(NotPermissionException.class)
    public Result<?> notPermission(NotPermissionException e) {
        return Result.fail(CodeMsgEnum.NOT_PERMISSION.status, e.getMessage());
    }

    @ExceptionHandler(NotBasicAuthException.class)
    public Result<?> notBasicAuth(NotBasicAuthException e) {
        return Result.fail(CodeMsgEnum.NOT_BASIC_AUTH.status, e.getMessage());
    }

    @ExceptionHandler(SaTokenException.class)
    public Result<?> saToken(SaTokenException e) {
        return Result.fail(CodeMsgEnum.SA_TOKEN.status, e.getMessage());
    }


}
